<template>
  <!-- 出租 -->
  <div class="app-container">
    <!-- 搜索 -->
    <com-title-item title="查询条件">
      <el-form
        ref="queryForm"
        class="el-form"
        :model="queryParams"
        :inline="true"
        size="mini"
        style="margin-top: 20px"
        label-width="120px"
      >
        <el-form-item label="小区名称">
          <!-- <el-input v-model="queryParams.resblock_name" placeholder="请输入小区名称" clearable style="width: 240px" /> -->
          <el-select
            v-model="queryParams.resblock_name"
            clearable
            filterable
            remote
            placeholder="请输入关键词"
            :remote-method="remoteMethodSearchArea"
            :loading="areaSearchOptions.loading"
            style="width: 240px"
          >
            <el-option
              v-for="item in areaSearchOptions.options"
              :key="item.resblockId"
              :label="item.resblockName"
              :value="item.resblockName"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="户型">
          <el-select v-model="queryParams.houseType" style="width: 240px" placeholder="请选择" clearable>
            <el-option
              v-for="dict in houseTypeOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="房源状态">
          <el-select v-model="queryParams.houseStatus" style="width: 240px" placeholder="请选择">
            <el-option
              v-for="dict in houseStatusOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="是否可推送">
          <el-select v-model="queryParams.delPercentage" style="width: 240px" placeholder="请选择" clearable>
            <el-option
              v-for="dict in pushAbleOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="录入时间">
          <el-date-picker
            v-model="queryParams.recordTime"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            size="mini"
            :editable="false"
            value-format="timestamp"
            :default-time="['00:00:00', '23:59:59']"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item style="margin-left: 50px">
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button plain type="primary" icon="el-icon-delete" size="mini" @click="handleReset">清空</el-button>
        </el-form-item>
      </el-form>
    </com-title-item>

    <!-- 列表 -->
    <div class="bg-white">
      <!-- 多选推送 -->
      <el-row type="flex" justify="end">
        <el-button
          size="small"
          plain
          :disabled="multipleSelection.length == 0"
          @click="onDelete"
          style="margin-top: 10px; margin-right: 10px"
          >删除</el-button
        >
        <el-button
          v-if="currentHouseStatus === 'UNAVAILABLE'"
          size="small"
          plain
          :disabled="multipleSelection.length == 0"
          @click="handlePutUpDown"
          style="margin-top: 10px; margin-right: 10px"
          >批量上架</el-button
        >
        <el-button
          v-if="currentHouseStatus === 'AVAILABLE'"
          size="small"
          plain
          :disabled="multipleSelection.length == 0"
          @click="handlePutUpDown"
          style="margin-top: 10px; margin-right: 10px"
          >批量下架</el-button
        >
        <el-button
          type="primary"
          size="small"
          :disabled="this.multipleSelection.length == 0"
          @click="handleGoPush"
          style="margin-top: 10px; margin-right: 10px"
          >推送房源</el-button
        >
      </el-row>
      <!-- 表格 -->
      <el-table
        v-loading="loading"
        border
        highlight-current-row
        :data="tableList"
        @selection-change="handleSelectionChange"
        style="margin-top: 10px"
        :header-cell-style="{ background: '#EDF6FF' }"
      >
        <!-- 选择框项 -->
        <el-table-column type="selection" width="55" align="center"></el-table-column>
        <!-- 多个信息项 -->
        <el-table-column
          v-for="(item, index) in tableTitles"
          :key="index"
          :label="item.title"
          :width="item.width"
          align="center"
        >
          <template slot-scope="{ row }">
            <template v-if="item.key == 'title'">
              <comHouseItem :key="row.hou_del_id" :model="row" />
            </template>
            <template v-else>
              <template v-if="item.keysList">
                <div v-for="innerItem in item.keysList" :key="innerItem.key">
                  <template v-if="row[innerItem.key]">
                    <el-button v-if="innerItem.key == 'push_state'" @click="lookLog(row.hou_del_id)" type="text">{{
                      innerItem.format ? innerItem.format(row[innerItem.key]) : row[innerItem.key]
                    }}</el-button>
                    <div v-else-if="innerItem.key == 'del_percentage'">
                      <div>{{ innerItem.format ? innerItem.format(row[innerItem.key]) : row[innerItem.key] }}</div>
                      <div v-if="row['del_percentage'] != '1'" @click="jumpToHouseDetail(row)">
                        <div>房源信息不完整，</div>
                        <el-button size="mini" type="text" class="text-blue fs-md">点击去完善</el-button>
                      </div>
                    </div>
                    <span v-else>{{
                      innerItem.format ? innerItem.format(row[innerItem.key]) : row[innerItem.key]
                    }}</span>
                  </template>
                </div>
              </template>
              <!-- 端口 -->
              <template v-else-if="item.isList">
                <div v-for="item in row.hou_port_info" :key="item.id">
                  {{ platform[item.portType] }}
                  {{ item.onePushFlag == '0' ? '满足' : '不满足' }}
                </div>
              </template>
              <template v-else>
                <el-checkbox v-if="item.checkAble" :disabled="row.disabled" v-model="row.selected"></el-checkbox>
                <template v-else>{{
                  ((item.format ? item.format(row[item.key]) : row[item.key]) || item.default) | showTxt
                }}</template>
              </template>
            </template>
          </template>
        </el-table-column>
        <!-- 操作项 -->
        <el-table-column label="操作" align="center" width="180" class-name="small-padding">
          <template slot-scope="{ row }">
            <template v-for="item in apparentOptionsList">
              <el-button
                v-if="item.matching(row)"
                :key="item.type"
                size="mini"
                type="text"
                @click="handleOptions(row, item.type, item.getId(row), item.menuId, item.handler)"
                >{{ item.title }}</el-button
              >
            </template>

            <el-dropdown v-if="!isNoMoreOptions(row)" @command="handleDownload" style="margin-left: 10px">
              <el-button size="mini" type="text">
                更多操作
                <i class="el-icon-arrow-down el-icon--right"></i>
              </el-button>
              <el-dropdown-menu slot="dropdown">
                <template v-for="(item, index) in moreOptionsList">
                  <el-dropdown-item
                    v-if="item.matching(row)"
                    :command="{
                      delId: item.getId(row),
                      type: item.type,
                      menuId: item.menuId,
                      ...row
                    }"
                    :key="index"
                    >{{ item.title }}</el-dropdown-item
                  >
                </template>
              </el-dropdown-menu>
            </el-dropdown>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <!-- 分页 -->
    <el-row type="flex" justify="end">
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.page"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-row>

    <!-- 查看房源日志 -->
    <com-log v-if="showLog" :houDelId="logHouDelId" @oncloselog="handleHideLog" />

    <!-- 补充室内图弹窗 -->
    <dialog-update-img
      v-if="dialogUpdateImgVisible"
      @ontoggle="handleToggleDialog"
      @onsaveimg="handleSaveImg"
      :tag-code="tagCode"
      :houDelId="currentHouDelId"
    ></dialog-update-img>

    <dialog-water-mark
      v-if="watermarkPopVisible"
      :houDelId="currentHouDelId"
      @onclose="handleCloseWaterPop"
    ></dialog-water-mark>
  </div>
</template>

<script>
import {
  myDelList,
  operateList,
  downloadPic,
  getOssfiles,
  getMemberPower,
  myDelListWeb,
  submitVrTask,
  updateImage,
  likeResblockName,
  downDelAndHmCooperationHouse,
  deleteHouseByIds
} from '../../api/user';
import platform from '@/config/house/platform';
import comHouseItem from './com/com-house-item';
import DialogUpdateImg from './dialog/dialog-update-img';
import pagination from '@/components/Pagination';
import DialogWaterMark from './dialog/dialog-water-mark';
import { parseDate } from '@/filters';
import { downLoadZip, downLoadVideo, toLine } from '@/utils/utilsNew';
import {
  DOWN_LOAD_PIC,
  DOWN_LOAD_FULL,
  DOWN_LOAD_VIDEO,
  HOUSE_PUSH,
  VR_COMPOUND_VIDEO,
  VR_COMPOUND_ADD,
  WATER_MARK
} from '@/config/menuId';
import { menuHandler, checkPortBindByCode } from '@/handler/menuHandler';
import { mapGetters } from 'vuex';
import comTitleItem from './com/com-title-item';
import comLog from './dialog/com-log';
import { PORT_CODE_AJK } from '@/config/house/platform';

export default {
  components: {
    comHouseItem,
    pagination,
    comTitleItem,
    comLog,
    DialogUpdateImg,
    DialogWaterMark
  },

  filters: {
    showTxt(txt) {
      return txt || '--';
    }
  },
  data() {
    return {
      watermarkPopVisible: false,
      //小区搜索加载中
      areaSearchOptions: {
        loading: false,
        options: []
      },
      currentHouseStatus: 'AVAILABLE',
      currentHouDelId: '',
      tagCode: '',
      dialogUpdateImgVisible: false,
      logHouDelId: '', //日志delid
      showLog: false,
      platform: Object.freeze(platform),
      multipleSelection: [],
      loading: false,
      total: 0,
      sendLogTotal: 20,
      tableList: [],
      // 查询参数
      queryParams: {
        page: 1,
        pageSize: 10,
        houseType: '',
        houseStatus: 'AVAILABLE',
        resblock_name: '',
        delPercentage: '', //是否可推送
        recordTime: []
      },
      sendLogQueryParams: {
        page: 1,
        pageSize: 10,
        houseType: '',
        houseStatus: 'AVAILABLE',
        resblock_name: ''
      },
      houseTypeOptions: [
        { dictValue: '1', dictLabel: '1室' },
        { dictValue: '2', dictLabel: '2室' },
        { dictValue: '3', dictLabel: '3室' },
        { dictValue: '4', dictLabel: '4室' },
        { dictValue: '5', dictLabel: '5室' },
        { dictValue: '6', dictLabel: '5室以上' }
      ],
      houseStatusOptions: [
        { dictValue: 'AVAILABLE', dictLabel: '上架' },
        { dictValue: 'UNAVAILABLE', dictLabel: '已下架' }
      ],
      pushAbleOptions: [
        { dictValue: 1, dictLabel: '是' },
        { dictValue: 2, dictLabel: '否' }
      ],
      tableTitles: [
        { title: '房源编号', width: '100', key: 'shulan_hou_num' },
        { title: '基础信息', width: 0, key: 'title' },
        {
          title: '是否可推送',
          width: '210',
          keysList: [
            {
              t: '是否可推送',
              key: 'del_percentage',
              format: (v) => (v == '1' ? '可推送' : '不可推送')
            }
          ]
        },
        {
          title: '推送信息',
          width: '150',
          keysList: [
            {
              t: '推送成功次数',
              key: 'push_count',
              format: (v) => `推送成功${v}次`
            },
            {
              t: '查看日志',
              key: 'push_state',
              format: (v) => {
                if (v == 'T') {
                  return `查看日志(推送中)`;
                }
                if (v == 'S') {
                  return `查看日志(推送成功)`;
                }
                if (v == 'F') {
                  return `查看日志(推送失败)`;
                }
              }
            }
          ]
        },
        {
          title: '时间',
          width: '200',
          keysList: [
            {
              t: '创建',
              key: 'create_time',
              format: function(v) {
                return this.t + ' ' + parseDate(v);
              }
            },
            {
              t: '更新',
              key: 'update_time',
              format: function(v) {
                return this.t + ' ' + parseDate(v);
              }
            },
            {
              t: '推送',
              key: 'push_time',
              format: function(v) {
                return this.t + ' ' + parseDate(v);
              }
            }
          ]
        },
        { title: '状态', width: '80', key: 'houseStatus' }
      ],
      apparentOptionsList: [
        {
          title: '推送房源',
          type: 'push',
          menuId: HOUSE_PUSH,
          matching: (row) => true,
          getId: (row) => row.hou_del_id
        },
        {
          title: '去除实勘牌',
          type: 'waterMark',
          menuId: WATER_MARK,
          matching: (row) => true,
          getId: (row) => row.hou_del_id,
          handler(row, type, id) {
            this.currentHouDelId = id;
            this.watermarkPopVisible = true;
          }
        },
        {
          title: '合成视频',
          type: 'vrToVideo',
          menuId: VR_COMPOUND_VIDEO,
          matching: (row) => true,
          getId: (row) => row.hou_del_id
        },
        {
          title: '补充室内图',
          type: 'additionRoomImg',
          menuId: null,
          matching: (row) => row.hou_sub_type == '1',
          getId: (row) => row.hou_del_id,
          handler(row, type, id) {
            if (this.vrDownLoadCheck(row) === true) {
              this.currentHouDelId = id;
              this.dialogUpdateImgVisible = true;
            }
          }
        }
      ],
      moreOptionsList: [
        {
          title: '修改',
          type: 'modify',
          matching: (row) => true,
          getId: (row) => row.hou_del_id
        },
        {
          title: '下载图片',
          type: 'pic',
          menuId: DOWN_LOAD_PIC,
          matching: (row) => !!row.img_id,
          getId: (row) => row.hou_del_id
        },
        {
          title: '下载全景图',
          type: 'pan',
          menuId: DOWN_LOAD_FULL,
          matching: (row) => row.sphere_status == '10',
          getId: (row) => row.hou_del_id
        },
        {
          title: '下载视频',
          type: 'vid',
          menuId: DOWN_LOAD_VIDEO,
          matching: (row) => row.video_material && row.video_material.videoId && row.video_status != '1',
          getId: (row) => row.video_material.videoId
        }
        // {
        //   title: "视频配音",
        //   type: "videoDubbed",
        //   menuId: VR_COMPOUND_VIDEO,
        //   matching: (row) => row.hou_sub_type == "1",
        //   getId: (row) => row.hou_del_id,
        // },
      ]
    };
  },
  computed: {
    isNoMoreOptions() {
      return (row) => Object.values(this.moreOptionsList).every((item) => !item.matching(row));
    },
    ...mapGetters(['sessionUser'])
  },

  mounted() {
    this.handleQuery();
  },

  methods: {
    handleCloseWaterPop(e) {
      this.watermarkPopVisible = false;
      // 刷新页面
      if (e) {
        this.handleQuery();
      }
    },
    remoteMethodSearchArea(query) {
      if (query !== '') {
        this.areaSearchOptions.loading = true;

        likeResblockName({
          keyWord: query,
          page: 1,
          pageSize: 99
        }).then(({ content }) => {
          this.areaSearchOptions.loading = false;
          this.areaSearchOptions.options = content.rows;
        });
      } else {
        this.areaSearchOptions.options = [];
      }
    },
    // 切换补充室内图弹窗
    handleToggleDialog(v) {
      this.dialogUpdateImgVisible = v;
    },

    // 点击保存补充室内图
    handleSaveImg(tagCode, newValue, otherList) {
      let houImgList = [...newValue, ...otherList];
      houImgList.forEach((item, index) => (item.cover = index));
      return updateImage({ houImgList })
        .catch((error) => {
          this.$message.error('图片保存超时！');
          return Promise.reject();
        })
        .then(({ isSuccess, errorMessage = '' }) => {
          if (!isSuccess) {
            return this.$messageBox.confirm(`保存图片失败，${errorMessage}`, {
              confirmButtonText: '我知道了',
              showCancelButton: false
            });
          } else {
            this.$message.success('图片保存成功！');
          }
        });
    },

    // 操作项（除更多操作之外的按钮）
    handleOptions(row, type, id, menuId, handler) {
      if (handler) {
        handler.apply(this, [...arguments]);
        return;
      }

      // 其他操作
      menuHandler
        .call(this, menuId)
        .then(() => {
          switch (type) {
            // 推房
            case 'push':
              this.pushHanlder(id);
              break;
            // vr转视频
            case 'vrToVideo':
              if (this.vrDownLoadCheck(row) === true) {
                this.vrToVideoHandler(id, row.video_material);
              }
              break;
            default:
              break;
          }
        })
        .catch((error) => {});
    },

    // 更多操作
    handleDownload(row) {
      const { delId, type, title, menuId, delegation_type } = row;
      // 修改房源
      if (type == 'modify') {
        return this.modifyHouseInfo(delId, delegation_type);
      }
      // 其他操作
      menuHandler
        .call(this, menuId)
        .then(() => {
          switch (type) {
            // 下载视频
            case 'vid':
              this.loadVideoHandler(delId, title, menuId);
              break;
            // 视频配音
            case 'videoDubbed':
              if (row.video_status == '1') {
                return this.$message.error('视频正在合成中，稍后再试～');
              }
              if (!(row.video_material && row.video_material.videoId)) {
                return this.$message.error('暂无视频可配音，请上传或合成视频后再试～');
              }
              if (this.vrDownLoadCheck(row) === true) {
                this.$router.push({
                  name: 'vrTurnVideo',
                  params: { houDelId: delId, required: '1' }
                });
              }
              break;
            // 下载图片
            default:
              this.loadimg(delId, type, title, menuId);
              break;
          }
        })
        .catch((error) => {});
    },

    // 下载视频
    loadVideoHandler(delId, title, menuId) {
      getOssfiles(delId, title).then(({ data }) => {
        this.$message.success('已开始下载，请稍后~');
        downLoadVideo(data);
        getMemberPower({
          menuId: menuId,
          agentId: this.sessionUser.id
        });
      });
    },

    // 关于vr是否下载的校验
    vrDownLoadCheck(row) {
      let state = row.hou_sub_type_state || row.houSubTypeState;
      let delId = row.hou_del_id;
      if (state == '1') {
        return this.$message.error('VR正在下载中，请等待VR下载完后使用～');
      }
      return true;
    },

    // 修改房源跳转
    modifyHouseInfo(delId, delegationType) {
      this.$router.push({
        name: delegationType == 'SALES' ? 'modifyHouseNew' : 'modifyHouse',
        params: { houDelId: delId }
      });
    },

    // vr合成视频
    vrToVideoHandler(delId, videoMaterial) {
      let p =
        videoMaterial && videoMaterial.videoId
          ? this.$messageBox.confirm('重新上传视频会替换现有视频，是否继续？', {
              confirmButtonText: '确定',
              cancelButtonText: '取消'
            })
          : Promise.resolve();
      p.then(() => {
        this.$router.push({
          name: 'vrTurnVideo',
          params: { houDelId: delId, required: '0' }
        });
      });
    },

    // 下载图片
    loadimg(delId, type, title, menuId) {
      downloadPic({ delId, type }).then(({ data }) => {
        this.$message.success('已开始下载，请稍后~');
        downLoadZip(data, title);
        getMemberPower({
          menuId: menuId,
          agentId: this.sessionUser.id
        });
      });
    },

    // 推送逻辑处理
    async pushHanlder(delId) {
      if (!(await checkPortBindByCode(PORT_CODE_AJK, true))) {
        this.noBindPortHandler('您暂无可推送的安居客端口账号，请先绑定后再进行推送~');
        return;
      }
      let item = this.tableList.find((v) => v.hou_del_id == delId);
      console.log('是否可推送', item.del_percentage);
      if (item.del_percentage == '1') {
        this.$router.push({
          name: 'sendHouse',
          query: { delId: [item.hou_del_id], delegationType: this.$route.name == 'rentHouse' ? 'RENT' : 'SALES' }
        });
      } else {
        this.$messageBox
          .confirm(`该房源信息不完善，暂时无法推送，请先完善房源信息～`, '系统提示：', {
            confirmButtonText: '去完善',
            cancelButtonText: '取消'
          })
          .then(() => {
            this.$router.push({
              name: 'modifyHouse',
              params: { houDelId: item.hou_del_id }
            });
          })
          .catch(() => {});
      }
    },

    // 查询房源列表
    async getList({ page }) {
      this.loading = true;
      const _data = this.queryParams;
      const params = {
        t: {
          delegationType: this.$route.name == 'rentHouse' ? 'RENT' : 'SALES',
          delPercentage: _data.delPercentage,
          resblockName: _data.resblock_name,
          room: _data.houseType || 0,
          state: _data.houseStatus || 'AVAILABLE',
          startDate: _data.recordTime ? _data.recordTime[0] : 0,
          endDate: _data.recordTime ? _data.recordTime[1] : 0
        },
        currentPage: page || this.queryParams.currentPage + 1,
        pageSize: _data.pageSize
      };
      if (!_data.delPercentage) {
        delete params.t.delPercentage;
      }
      const { content } = await myDelListWeb(params);

      this.queryParams.page = params.currentPage;
      this.total = content.total || 0;
      this.tableList = content.pages.map((item, index) => {
        const tag = this.queryParams.houseStatus || 'AVAILABLE';
        item.createTime = item.delCreateTime;
        item.updateTime = item.delUpdateTime;
        item.houDelId = item.delId;
        delete item.delCreateTime;
        delete item.delUpdateTime;
        delete item.delId;
        item.pushFlag = item.pushFlag || '1';
        item.pushCount = item.pushCount || '0';
        item.houPortInfo = this.houPortMakeUp(item.houPortInfo);
        item.delPercentage = item.houPortInfo[0].delPercentage || '0';
        item = Object.keys(item).reduce((obj, key) => {
          // 此处历史原因
          obj[toLine(key)] = item[key];
          return obj;
        }, {});
        item.selected = false;
        item.disabled = item.del_percentage != '1';
        item.houseStatus = tag == 'AVAILABLE' ? '上架' : '下架';

        return item;
      });
      this.loading = false;
    },

    //填补缺少的关于平台推房相关信息
    houPortMakeUp(info = []) {
      return Object.keys(platform).map((key) => {
        return (
          info.find((v) => v.portType == key) || {
            portType: key,
            onePushFlag: '1'
          }
        );
      });
    },

    // 搜索按钮操作
    handleQuery() {
      this.currentHouseStatus = this.queryParams.houseStatus;
      this.getList({ page: 1 });
      // operateList();
    },

    // 多选推送
    handleGoPush() {
      let len = this.multipleSelection.length;
      menuHandler
        .call(this, HOUSE_PUSH, len)
        .then(async () => {
          if (!(await checkPortBindByCode(PORT_CODE_AJK, true))) {
            this.noBindPortHandler('您暂未绑定可推送的安居客端口账号，请先绑定后再进行推送~');
            return;
          }
          this.$router.push({
            name: 'sendHouse',
            query: {
              delId: this.multipleSelection,
              delegationType: this.$route.name == 'rentHouse' ? 'RENT' : 'SALES'
            }
          });
        })
        .catch(() => {});
    },

    // 未绑定端口处理
    noBindPortHandler(err) {
      this.$messageBox
        .confirm(err || `您还未绑定端口账号，请先绑定后再进行推送~`, '系统提示：', {
          confirmButtonText: '去绑定',
          cancelButtonText: '取消'
        })
        .then(() => {
          this.$router.push({ name: 'portManagement' });
        })
        .catch(() => {});
    },

    // 处理选择框
    checkboxT(row, index) {
      return !row.disabled;
    },

    // 列表多选改变
    handleSelectionChange(val) {
      this.multipleSelection = val.map((v) => v.hou_del_id);
    },

    // 重置列表数据
    handleReset() {
      this.queryParams = {
        page: 1,
        pageSize: 20,
        houseType: '',
        houseStatus: 'AVAILABLE',
        resblock_name: '',
        delPercentage: ''
      };
    },

    // 打开日志
    lookLog(houdelId) {
      this.logHouDelId = houdelId;
      this.showLog = true;
    },

    // 关闭日志
    handleHideLog() {
      this.showLog = false;
      this.getList({ page: this.queryParams.page });
    },

    // 跳转房源详情
    jumpToHouseDetail(row) {
      const { hou_del_id, delegation_type } = row;
      this.modifyHouseInfo(hou_del_id, delegation_type);
    },

    async handlePutUpDown() {
      try {
        let t = this;
        let { multipleSelection, currentHouseStatus } = t;
        t.$confirm(`您确定要${currentHouseStatus === 'AVAILABLE' ? '下架' : '上架'}房源?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消'
        })
          .then(async () => {
            let res = await downDelAndHmCooperationHouse({
              delId: multipleSelection.join(),
              state: currentHouseStatus === 'AVAILABLE' ? 'UNAVAILABLE' : 'AVAILABLE',
              invalidType: '1'
            });
            if (res && res.isSuccess) {
              t.$alert(res.content.msg, '提示', {
                showClose: false,
                confirmButtonText: '确定'
              });
            } else {
              t.$alert(`${currentHouseStatus === 'AVAILABLE' ? '下架' : '上架'}失败,请稍后再试!`, '提示', {
                showClose: false,
                confirmButtonText: '确定'
              });
            }
            t.getList({ page: 1 });
          })
          .catch(() => {});
      } catch (error) {}
    },

    async onDelete() {
      try {
        const { multipleSelection, queryParams } = this;
        this.$confirm('是否确认删除房源?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消'
        }).then(async () => {
          let res = await deleteHouseByIds({
            ids: multipleSelection
          });
          if (res && res.isSuccess && res.content) {
            this.$message.success(`已成功删除${res.content.successCount}套，失败${res.content.errorCount}套`);
            this.getList({ page: 1 });
          } else {
            this.$message.error('房源删除失败，请检查房源状态');
          }
        });
      } catch (error) {}
    }
  }
};
</script>

<style scoped>
.app-container {
  background: #f6f6f6;
}
.reset-button {
  border-color: #fff;
  background: transparent;
  cursor: auto;
  text-align: left;
  padding: 0;
  line-height: 20px;
}
.reset-button:hover {
  background-color: transparent;
  border-color: transparent;
}
.pagination-container {
  padding: 0;
}
.main-item {
  display: flex;
  justify-content: space-between;
}
.close-sendlog {
  cursor: pointer;
}

.pagination-container {
  background: none;
}
</style>
